package com.alipay.app.groupmeal.standard.offline.manager;

import com.alipay.app.groupmeal.standard.offline.DbService;
import com.alipay.app.groupmeal.standard.offline.bean.SbruanDinnerBean;
import com.alipay.app.groupmeal.standard.offline.bean.SbruanDinnerBeanDao;

import java.util.List;

public class SbruanDinnerDataManager {

    private SbruanDinnerBeanDao mDao;

    public static SbruanDinnerDataManager getInstance() {
        SbruanDinnerDataManager.DataManagerHolder.mInstance.mDao
                = DbService.getDaoSession().getSbruanDinnerBeanDao();
        return SbruanDinnerDataManager.DataManagerHolder.mInstance;
    }

    private static class DataManagerHolder {
        private static final SbruanDinnerDataManager mInstance = new SbruanDinnerDataManager();
    }

    public long insert(SbruanDinnerBean bean) {
        return mDao.insert(bean);
    }

    public void insertInTx(List<SbruanDinnerBean> beanList) {
        mDao.insertInTx(beanList);
    }

    public void deleteAll() {
        mDao.deleteAll();
    }

    public void insertInTxForDelete(List<SbruanDinnerBean> beanList) {
        long count = mDao.count();
        if (count > 0) {
            mDao.deleteAll();
        }
        mDao.insertInTx(beanList);
    }
}
